package com.jcl.recruit.user.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.resume.vo.ResumeSimpleResultEntity;
import com.jcl.recruit.user.dao.UserResumeAttentionDao;
import com.jcl.recruit.user.model.UserResumeAttention;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName UserResumeAttentionLogic

 * @Author yyliu
 * @Date 2018/10/23 14:06
 * @Version 1.0
 **/
@Component
public class UserResumeAttentionLogic {

    @Autowired
    private UserResumeAttentionDao userResumeAttentionDao;


    public List<ResumeSimpleResultEntity> changeResumeAttentionList(Integer userId,
                                                                    List<ResumeSimpleResultEntity> resumeList) {
        if (CollectionUtils.isNotEmpty(resumeList)) {
            List<Integer> ids = new ArrayList<>();
            for (ResumeSimpleResultEntity entity : resumeList) {
                ids.add(entity.getId());
            }
            List<UserResumeAttention> attentions = getListBySearchResumeIds(userId, ids);

            List<String> attentionResumeIds = new ArrayList<>();
            if (!CollectionUtils.isEmpty(attentions)) {
                for (UserResumeAttention attention : attentions) {
                    attentionResumeIds.add(attention.getSearchResumeId().toString());
                }
            }
            for (ResumeSimpleResultEntity entity : resumeList) {
                if (attentionResumeIds.contains(entity.getId())) {
                    entity.setAttention(true);
                }
            }
        }

        return resumeList;
    }

    public List<UserResumeAttention> getListBySearchResumeIds(Integer userId, List<Integer> searchResumeIds) {
        return userResumeAttentionDao.getListBySearchResumeIds(userId, searchResumeIds);
    }

    public List<UserResumeAttention> getListBySearchResumeId(Integer userId, Integer searchResumeId) {
        return userResumeAttentionDao.getListBySearchResumeId(userId, searchResumeId);
    }

    public List<UserResumeAttention> getListByUserId(Integer userId) {
        return userResumeAttentionDao.getListByUserId(userId);
    }

    public List<UserResumeAttention> getListByResumeId(Integer userId, Integer resumeId) {
        return userResumeAttentionDao.getListByResumeId(userId, resumeId);
    }

    public List<UserResumeAttention> getListByOtherJid(Integer userId, String otherJid) {
        return userResumeAttentionDao.getListByOtherJid(userId, otherJid);
    }

    public UserResumeAttention findOne(Integer id) {
        return userResumeAttentionDao.findOne(id);
    }

    public int update(Integer id, Integer status) {
        return userResumeAttentionDao.update(id, status);
    }

    public int add(UserResumeAttention attention) {
        return userResumeAttentionDao.add(attention);
    }
}
